package com.liu.user.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.user.entity.base.UserPermissionInfo;
import com.liu.user.entity.dto.UserPermissionInfoDTO;
import com.liu.user.mapper.UserPermissionInfoMapper;
import com.liu.user.service.IUserPermissionInfoService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiuChengLong
 * @since 2022-09-21
 */
@Service
public class UserPermissionInfoServiceImpl extends ServiceImpl<UserPermissionInfoMapper, UserPermissionInfo> implements IUserPermissionInfoService {

    @Override
    public List<UserPermissionInfoDTO> getUserPermission(String userId) {
        return baseMapper.getUserPermission(userId);
    }

    @Override
    public void saveUserPermission(UserPermissionInfo userPermissionInfo) {
        List<UserPermissionInfoDTO> userPermission = baseMapper.getUserPermission(String.valueOf(userPermissionInfo.getUserId()));
        List<String> userPermissionIdList = userPermission.stream().map(UserPermissionInfoDTO::getPermissionId).collect(Collectors.toList());
        if (CollUtil.isEmpty(userPermissionIdList)) {
            baseMapper.insert(userPermissionInfo);
        }
    }


}
